package com.ourteam.system.api;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.system.dao.SysRoleDAOQueryBean;
import com.ourteam.system.domain.SystemRole;

public class SystemRoleSearchModel extends AbstractSearchModel<SysRoleDAOQueryBean> {

	private Long domainId;

	private String roleCode;

	private String roleName;

	private long[] excludeIds;

	@Override
	public String getMappedDAOField(String aProperty) {
		return SystemRole.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(SysRoleDAOQueryBean queryBean) throws Exception {

		SysRoleDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		if (this.domainId != null && this.domainId != 0) {
			criteria.andDomainIdEqualTo(domainId);
		}

		if (StringUtils.isNotBlank(roleCode)) {
			criteria.andRoleCodeLike(roleCode);
		}

		if (StringUtils.isNotBlank(roleName)) {
			criteria.andRoleNameLike(roleName);
		}

		if (ArrayUtils.isNotEmpty(this.excludeIds)) {
			criteria.andIdNotIn(excludeIds);
		}

		// queryBean.setSortProperty(ISysRoleDAO.DomainCode, aIsAsc);

	}

	public String getRoleCode() {
		return roleCode;
	}

	public void setRoleCode(String roleCode) {
		this.roleCode = roleCode;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public long[] getExcludeIds() {
		return excludeIds;
	}

	public void setExcludeIds(long[] excludeIds) {
		this.excludeIds = excludeIds;
	}

	public Long getDomainId() {
		return domainId;
	}

	public void setDomainId(Long domainId) {
		this.domainId = domainId;
	}

}
